from itsdangerous import TimedJSONWebSignatureSerializer as Serializer, BadData
from django.conf import settings

# 生成一个邮件验证token
def encode_signature_mail_url(data):
    serializer = Serializer(settings.SECRET_KEY, 300)
    token = serializer.dumps(data)
    return token.decode()


# 解密邮件链接
def decode_signature_mail_url(token):
    serializer = Serializer(settings.SECRET_KEY, 300)
    try:
        data = serializer.loads(token)
    except Exception as e:
        return None
    return data